{% extends "base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load dv_filters %}
{% block head_title %}{% trans "Session" %} {{ session.day|date }}{% if session.begin %}, {{ session.begin|time }}{% endif %}{% endblock %}

{% block content %}
    {% include 'challenge/session_header.html' with session=session only %}

    <nav class="hidden-print">
        <ul class="pager">
        {% if session_previous and user|can:'challenge_session_crud' or session_previous.visible or session_previous.orga.coordinator == user %}
            <li class="previous btn-xs">
                <a href="{% url 'session-detail' seasonpk=season.pk pk=session_previous.pk %}" title="{{ session_previous }}">
                    <span aria-hidden="true">&larr;</span> {{ session_previous.short }}
                </a>
            </li>
        {% endif %}
            <li class="btn-xs">
                <a href="{% url 'season-detail' pk=season.pk %}">{% trans "Toutes les sessions" %}</a>
            </li>
        {% if session_next and user|can:'challenge_session_crud' or session_next.visible or session_next.orga.coordinator == user %}
            <li class="next btn-xs">
                <a href="{% url 'session-detail' seasonpk=season.pk pk=session_next.pk  %}" title="{{ session_next }}">
                    {{ session_next.short }}<span aria-hidden="true">&rarr;</span>
                </a>
            </li>
        {% endif %}
        </ul>
    </nav>

    {% if statemanager_can_access or coordinator_can_access %}
        <div class="hidden-print pull-right">
            <a class="btn btn-default" title="{% trans "Dupliquer" %}" href="{% url 'session-clone' seasonpk=season.pk pk=session.pk %}"><span class="glyphicon glyphicon-copy"></span></a>
            <a class="btn btn-primary" href="{% url 'session-update' seasonpk=season.pk pk=session.pk %}">{% trans "Éditer" %}</a>
        </div>
    {% endif %}
    <h2 class="hidden-print">{% trans "Session" %}</h2>

    <table class="table table-condensed">
    <tr><th>{% trans "Établissement" %}</th>
        <td>{% if user|can:'orga_crud' %}
              <a href="{% url 'organization-detail' session.orga.pk %}">{{ session.orga }}</a>
            {% else %}
              {{ session.orga }}
            {% endif %}
            {% if session.orga.coordinator.get_full_name %}
                <br />
                <small>{{ session.orga.coordinator.get_full_name }}
                    {% if session.orga.coordinator.profile.natel %}
                        <br class="hidden-print"/><span class="visible-print-inline"> |</span>
                        {{ session.orga.coordinator.profile.natel|tel_link }}
                    {% endif %}
                    {% if session.orga.coordinator.profile.phone %}
                        <br class="hidden-print"/><span class="visible-print-inline"> |</span>
                        {{ session.orga.coordinator.profile.phone|tel_link }}
                    {% endif %}
                </small>
            {% endif %}
        </td>
    </tr>
    <tr><th>{% trans "Emplacement de la session" %}</th>
        <td>{% if session.place %}<em>{{ session.place }}</em><br />{% endif %}
            {{ session.address_street }} {{ session.address_no }}<br />
            {{ session.address_city }}{% if session.canton %} ({{ session.address_canton }}){% endif %}
        </td>
    </tr>
    <tr class="hidden-print"><th>{% trans "Date" %}</th><td>{{ session.day|date:"l, j F Y" }}</td></tr>
    {% if session.begin and session.duration %}
        <tr><th>{% trans "Horaire" %}</th><td>{{ session.begin|time }} - {{ session.end|time }}</td></tr>
    {% endif %}
    {% if session.superleader %}
        <tr><th>{% trans "Moniteur + / Photographe" %}</th><td>{{ session.superleader|profile_tag:user_is_coordinator }}</td></tr>
    {% endif %}
    {% if session.fallback %}
        <tr><th>{% trans "Mauvais temps" %}</th><td>{{ session.fallback }}</td></tr>
    {% endif %}
    {% if session.n_bikes > 0 or session.n_helmets > 0 %}
        <tr><th>{% trans "Vélos" %}</th>
            <td>{% if session.n_bikes > 0 %}
                    {% blocktrans count n=session.n_bikes %}1 vélo{% plural %}{{ n }} vélos{% endblocktrans %}
                {% endif %}
                {% if session.n_helmets > 0 %}<br class="hidden-print" /><span class="visible-print-inline"> &amp;</span>
                    {% blocktrans count n=session.n_helmets %}1 casque{% plural %}{{ n }} casques{% endblocktrans %}
                {% endif %}
            </td>
        </tr>
    {% endif %}
    {% if session.apples or session.bikes_concept or session.bikes_phone %}
        <tr><th>{% trans "Logistique" %}</th>
            <td><dl class="dl-horizontal small">
                    {% if session.apples %}
                        <dt>{% trans "Pommes" %}</dt>
                            <dd>{{ session.apples }}</dd>
                    {% endif %}
                    {% if session.bikes_concept or session.bikes_phone %}
                        <dt>{% trans "Logistique vélos" %}</dt>
                            <dd>
                            {{ session.bikes_concept }}{% if session.bikes_concept and session.bikes_phone %}<br />{% endif %}
                            {{ session.bikes_phone|tel_link }}
                            </dd>
                    {% endif %}
                </dl>
            </td>
        </tr>
    {% endif %}
    <tr><th><a href="{% url 'session-staff-choices' season.pk session.pk %}" title="{% trans "Disponibilités" %}">{% trans "Moniteurs" %}</a></th>
        <td><dl class="dl-horizontal small">
                <dt>{% trans "Rendez-vous" %}</dt>
                    <dd>{{ session.helpers_time_with_default }}{% if session.helpers_place %}<br />{{ session.helpers_place }}{% endif %}</dd>
                {% if session.replacement_staff.count > 0 %}
                    <dt>{% trans "Moniteur de Secours" %}</dt>
                        <dd>{% for avail in session.replacement_staff %}{% if not forloop.first %}<br />{% endif %}{{ avail.helper|profile_tag:user_is_coordinator }}{% endfor %}</dd>
                {% endif %}
            </dl>
        </td>
    </tr>

    {% if session.errors and statemanager_can_access or session.errors and coordinator_can_access %}
        <tr class="hidden-print"><th>{% trans "Erreurs" %}</th><td>{{ session.errors }}</td></tr>
    {% endif %}
    {% if session.comments %}
        <tr><th>{% trans "Remarques" %}</th><td>{{ session.comments }}</td></tr>
    {% endif %}
    </table>
    {% if statemanager_can_access %}
      <div class="hidden-print pull-right">
          <a class="btn btn-primary" href="{% url 'season-availabilities' pk=season.pk %}#sess{{session.pk}}">{% trans "Planning" %}</a>
          {% if session_mailtoall %}
              <a class="btn btn-info" href="{{ session_mailtoall }}" target="_blank"><span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> {% trans "Email à l’équipe des Qualifs" %}</a>
          {% endif %}
      </div>
    {% endif %}
    <h2 class="hidden-print">{% trans "Qualifs" %}</h2>
    <table class="table">
    {% if session.qualifications.count > 0 %}
        <tr><th>{% trans "Classe" %}</th>
            {% for quali in session.qualifications.all %}
                <th>{% if not quali.errors %}{% include "ok.html" %}{% endif%}
                {{ forloop.counter }} - {% if statemanager_can_access or coordinator_can_access %}<a href="{% url 'quali-update' seasonpk=season.pk sessionpk=session.pk pk=quali.pk %}">{{ quali.name }}</a>{% else %}{{ quali.name }}{% endif %}
                {% if quali.errors and statemanager_can_access or quali.errors and coordinator_can_access %}<span class="hidden-print">
                    <br />
                    {{ quali.errors }}</span>
                {% endif %}
                </th>
            {% endfor %}
        </tr>
        <tr><td></td>
                {% for quali in session.qualifications.all %}
                    <td>{{ quali.class_teacher_fullname }}<br />
                        <small>{{ quali.class_teacher_natel|tel_link }}</small>
                        {% if quali.n_participants %}<br />
                            {% blocktrans with n=quali.n_participants %}{{ n }} participants{% endblocktrans %}
                        {% endif %}
                    </td>
                {% endfor %}
        </tr>
        <tr><th>{% trans "Nombre de moniteurs" %}</th>{% for quali in session.qualifications.all %}<td>{{ quali.n_helpers }}</td>{% endfor %}</tr>
        <tr><th>{% trans "Moniteur 2" %}</th>
                {% for quali in session.qualifications.all %}<td>{{ quali.leader|profile_tag:user_is_coordinator }}</td>{% endfor %}</tr>
        <tr><th>{% trans "Moniteurs 1" %}</th>
                {% for quali in session.qualifications.all %}<td>{% for helper in quali.helpers.all %}{{ helper|profile_tag:user_is_coordinator }}<br />{% endfor %}</td>{% endfor %}</tr>
        <tr><th>{% trans "Agilité" %}</th>
                {% for quali in session.qualifications.all %}<td><em>{{ quali.activity_A|default:"" }}</em></td>{% endfor %}</tr>
        <tr><th>{% trans "Mécanique" %}</th>
                {% for quali in session.qualifications.all %}<td><em>{{ quali.activity_B|default:"" }}</em></td>{% endfor %}</tr>
        <tr><th>{% trans "Rencontre" %}</th>
                {% for quali in session.qualifications.all %}
                    <td>
                    <em>{{ quali.activity_C|default:"" }}</em><br />
                    {{ quali.actor|profile_tag:user_is_coordinator }}
                    </td>
                {% endfor %}
        </tr>
        <tr><th>{% trans "Parcours" %}</th>
                {% for quali in session.qualifications.all %}<td><em>{{ forloop.counter|lettercounter }}</em></td>{% endfor %}</tr>
        <tr><th>{% trans "Vélos" %}</th>
                {% for quali in session.qualifications.all %}
                    <td>{% if quali.n_bikes %}
                            {% blocktrans count n=quali.n_bikes %}1 vélo{% plural %}{{ n }} vélos{% endblocktrans %}
                        {% endif %}
                        {% if quali.n_helmets %}<br class="hidden-print" /><span class="visible-print-inline"> &amp;</span>
                            {% blocktrans count n=quali.n_helmets %}1 casque{% plural %}{{ n }} casques{% endblocktrans %}
                        {% endif %}
                    </td>
                {% endfor %}
        </tr>
        <tr><th>{% trans "Remarques" %}</th>
                {% for quali in session.qualifications.all %}<td><em>{{ quali.comments }}</em></td>{% endfor %}</tr>

        {% if statemanager_can_access or coordinator_can_access %}
            <tr class="hidden-print"><td></td>
                    {% for quali in session.qualifications.all %}
                        <td>
                            <a class="btn btn-primary btn-xs" href="{% url 'quali-update' seasonpk=season.pk sessionpk=session.pk pk=quali.pk %}">
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>{% trans "Éditer" %}
                            </a>
                            {% if statemanager_can_access %}
                                <br />
                                <a class="btn btn-danger btn-xs" href="{% url 'quali-delete' seasonpk=season.pk sessionpk=session.pk pk=quali.pk %}">
                                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>{% trans "Supprimer" %}
                                </a>
                            {% endif %}
                        </td>
                    {% endfor %}
            </tr>
        {% endif %}
    {% endif %}

    {% if statemanager_can_access %}
        <tr class="hidden-print">
            <td{% if session.qualifications.count > 0 %} colspan="{{ session.qualifications.count|add:1 }}"{% endif %}>
                <form method="POST" action="{% url 'quali-create' seasonpk=season.pk sessionpk=session.pk %}" class="form-horizontal">
                    {% csrf_token %}
                    {{ quali_form_quick }}
                    {% buttons %}<button type="submit" class="btn btn-primary pull-right">{% trans "Créer une Qualif’" %}</button>{% endbuttons %}
                </form>
            </td>
        </tr>
    {% endif %}
    </table>

    <div class="hidden-print">
        {% if season.manager_can_crud and user|can:'challenge_session_crud' %}
            <a class="btn btn-danger pull-right" href="{% url 'session-delete' seasonpk=season.pk pk=session.pk %}">{% trans "Supprimer" %}</a>
        {% endif %}
        <div class="btn-group" role="group" aria-label="exports">
            {% include 'export_buttons.html' with exporturl='session-export' seasonpk=season.pk exportargs=session.pk filter_querystring=filter_querystring pdf_file_name=pdf_file_name only %}
        </div>
        <a class="btn btn-default" href="{% url 'season-detail' pk=season.pk %}">{% trans "Retour au mois" %}</a>
    </div>
{% endblock %}
